package com.systemdevelopment.mainproject.View.Visitor;

import com.jfoenix.controls.JFXButton;
import com.systemdevelopment.mainproject.Model.Author;
import com.systemdevelopment.mainproject.Model.Book;
import com.systemdevelopment.mainproject.View.mainUI;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;

import java.util.HashSet;

public class bookContentController  {

    @FXML
    private JFXButton borrowButton;

    @FXML
    private ImageView image;

    @FXML
    private Label ISBN;

    @FXML
    private Label authorName;

    @FXML
    private ChoiceBox<String> time;

    @FXML
    private Label profile;

    @FXML
    private Label publisher;

    @FXML
    private Label bookName;

    @FXML
    public void initialize() {
        ObservableList<String> langs = FXCollections.observableArrayList("7天", "15天","30天", "60天", "90天");
        time.setItems(langs);
        HashSet<Author> authors= mainUI.CurBook.getAuthor();
        for(Author author:authors)
        {
            authorName.setText(author.getName());
            break;
        }
        bookName.setText(mainUI.CurBook.getName());
        publisher.setText(mainUI.CurBook.getPublisher());
        ISBN.setText(mainUI.CurBook.getISBN());
        profile.setText("简介:");
        profile.setText(profile.getText()+mainUI.CurBook.getIntroduction());
        profile.setWrapText(true);
        image.setImage(mainUI.CurBook.getImage());
    }

    @FXML
    void onBorrowAction(ActionEvent event) {
        int ti=0;
        if(time.getValue().equals("7天"))
            ti=7;
        if(time.getValue().equals("15天"))
            ti=15;
        if(time.getValue().equals("30天"))
            ti=30;
        if(time.getValue().equals("60天"))
            ti=60;
        if(time.getValue().equals("90天"))
            ti=90;
        mainUI.userController.borrowBook(mainUI.CurBook,ti);
    }
}
